/**
 *
 * @class ObjectMbsRenderer
 *
 * @brief Renders the MBS using the supplied geometries. Basically, with each link
 * 	there is an ModelOBJ object associated. The transformation matrix specifies
 *  the location of the object mesh.
 *
 * @date 26.08.2011
 *
 * @author Tomasz Rudny (rudny@gmail.com)
 * @version 1.0
 */

#ifndef OBJECTMBSRENDERER_H_
#define OBJECTMBSRENDERER_H_

/*
 *
 */
#include <stack>
#include <cstdio>
#include <map>

#include <GL/glut.h>

#include "MbsRenderer.h"
#include "ObjModel.h"

#include "MatVec.h"
#include "Sphere.h"
#include "Frame.h"

namespace graph {

class ObjectMbsRenderer: public graph::MbsRenderer {
public:
	ObjectMbsRenderer();
	virtual ~ObjectMbsRenderer();
	void renderMBS();
	void recursiveUpdate(const RSIM::RigidBodyNode * Nd, const RSIM::Vect3& V);
	void setMBS(RSIM::MultibodySystem * _mbs);
	void loadMesh(const char *meshFile, int position);
	void updateTransformations();
	//-------------------------------------------------------------------------
	// how many meshes (objects) there will be?
	//-------------------------------------------------------------------------
	void setMeshCount(int count);
	//------------------------------------------------------------------------------
	// Assign the mesh number to the ID (number) of the body in MBS
	//------------------------------------------------------------------------------
	void assignMesh(int meshNumber, int bodyID);
private:
	//-------------------------------------------------------------------------
	// Objects (meshes) associated with each link of the MBS
	//-------------------------------------------------------------------------
	ModelOBJ * meshes;
	//-------------------------------------------------------------------------
	// Transformations associated with each link of the MBS - for rendering
	//-------------------------------------------------------------------------
	RSIM::Transform *trans;
	//-------------------------------------------------------------------------
	// Stack of transformations to be rendered
	//-------------------------------------------------------------------------
	stack<RSIM::Transform> transStack;
	//-------------------------------------------------------------------------
	// The number of meshes to be used
	//-------------------------------------------------------------------------
	int meshCount;
	//-------------------------------------------------------------------------
	// The map between Body Links and Meshes
	//-------------------------------------------------------------------------
	map<int, int> meshMap;
};

}

#endif /* OBJECTMBSRENDERER_H_ */
